package com.toplabs.unashu.exception;

import com.toplabs.unashu.common.response.ResponseStatus;
import com.toplabs.unashu.common.response.StatusCode;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * @author toplabs
 * @since 2022/11/21
 * <p>This java file was created by toplabs in 2022/11/21.
 * The following is the description information about this file:</p>
 * <p>description: 业务异常</p>
 */
@Getter
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException implements StatusCode {
    private static final long serialVersionUID = -1453182903258874391L;
    /**
     * 错误码
     */
    private final int code;
    /**
     * 错误信息
     */
    private final String message;

    public ServiceException(String message) {
        super(message);
        this.code = ResponseStatus.FAILED.getCode();
        this.message = message;
    }

    public ServiceException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public ServiceException(StatusCode statusCode) {
        super(statusCode.getMessage());
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
    }

    public ServiceException(StatusCode statusCode, String msg) {
        super(msg);
        this.code = statusCode.getCode();
        this.message = msg;
    }

}